package com.sp.study.model.entity;

/**
 * <h1>
 *
 * </h1>
 *
 * @author Sp
 * @date 2020/9/16 - 19:39
 * @since 2020/9/16 - 19:39 星期三 by Sp Sp287940@163.com
 */
public class BookShelfIterator implements Iterator {

    /**
     * 创建BookShelf对象
     */
    private BookShelf bookShelf;
    private int index;

    public BookShelfIterator(BookShelf bookShelf) {
        this.bookShelf = bookShelf;
        this.index = 0;
    }

    @Override
    public boolean hasNext(){
        /**
         * 判断book序列是否小于书架总长度
         */
        if (index < bookShelf.getLength()){
            return true;
        } else {
            return false;
        }
    }

    @Override
    public Object next(){
        Book book = bookShelf.getBookAt(index);
        index++;
        return book;
    }
}
